import { Effect } from 'umi';
import { getDynamicMessage } from '@/server/friend';

export interface FriendState {
  data: {};
  list: {};
  emiLogin: {};
}

export interface FriendModelType {
  namespace: string;
  state: FriendState;
  effects: {
    fetchGetMessageList: Effect;
    //   fetchLogincaptcha: Effect;
    //   fetchEmiLogin:Effect;
  };
  reducers: any;
}

const Friend: FriendModelType = {
  namespace: 'friend',
  state: { data: {}, list: {}, emiLogin: {} },
  effects: {
    //
    *fetchGetMessageList({ payload, callback }: any, { put, call }: any) {
      const data = yield call(getDynamicMessage);
      yield put({
        type: 'setMessageList',
        payload: data,
      });
    },

    //   *fetchLogincaptcha({ payload }, { put, call }: any) {
    //     console.log(payload, 'payload');
    //     const data = yield call(Logincaptcha, payload);
    //     yield put({
    //         type: 'setLogincaptcha',
    //         payload: data,
    //     });
    //   },
    //   *fetchEmiLogin({ payload }, { put, call }: any) {
    //     const data = yield call(apiEmiLogin, payload);
    //     yield put({
    //         type: 'setEmiLogin',
    //         payload: data,
    //     });
    //   },
  },
  reducers: {
    setMessageList(state: FriendState, { payload }: any) {
      return { ...state, list: payload };
    },
  },
};

export default Friend;
